package cloud.seri.auth.domain

import com.fasterxml.jackson.annotation.JsonBackReference
import org.springframework.data.annotation.Id
import org.springframework.data.mongodb.core.mapping.DBRef
import org.springframework.data.mongodb.core.mapping.Document
import org.springframework.data.mongodb.core.mapping.Field
import java.io.Serializable
import java.util.*
import javax.validation.constraints.NotNull
import javax.validation.constraints.Size

/**
 * A Menu.
 */
@Document(collection = "menu")
class Menu(

    @Id
    var id: String? = null,

    @get: NotNull
    @get: Size(max = 30)
    @Field("text")
    var text: String? = null,

    @Field("i_18_n")
    var i18n: String? = null,

    @Field("group")
    var group: Boolean? = null,

    @Field("link")
    var link: String? = null,

    @Field("external_link")
    var externalLink: String? = null,

    @Field("target")
    var target: String? = null,

    @Field("icon")
    var icon: String? = null,

    @Field("disabled")
    var disabled: Boolean? = null,

    @Field("hide")
    var hide: Boolean? = null,

    @Field("hide_in_breadcrumb")
    var hideInBreadcrumb: Boolean? = null,

    @DBRef
    @Field("parent")
    @JsonBackReference
    var parent: Menu? = null
) : Serializable
{
    override fun equals(other: Any?): Boolean
    {
        if (this === other) return true
        if (other !is Menu) return false
        if (other.id == null || id == null) return false

        return Objects.equals(id, other.id)
    }

    override fun hashCode(): Int
    {
        return 31
    }

    override fun toString(): String
    {
        return "Menu{" +
            "id=$id" +
            ", text='$text'" +
            ", i18n='$i18n'" +
            ", group='$group'" +
            ", link='$link'" +
            ", externalLink='$externalLink'" +
            ", target='$target'" +
            ", icon='$icon'" +
            ", disabled='$disabled'" +
            ", hide='$hide'" +
            ", hideInBreadcrumb='$hideInBreadcrumb'" +
            "}"
    }

    companion object
    {
        private const val serialVersionUID = 1L
    }
}
